//
//  SellerPreFectureTableViewController.m
//  EasyToTesco2.0
//
//  Created by 袖手旁觀 on 16/6/21.
//  Copyright © 2016年 EasyToTesco. All rights reserved.
//

#import "SellerPreFectureTableViewController.h"
#import "SellerCooperateTableViewController.h"
#import "TurnOverItemizedTableViewController.h"
#import "TurnOverBalanceTableViewController.h"
#import "cooperateRecodeViewController.h"
#import "SellRecodeTableViewController.h"
#import "AccountChangeController.h"
#import "AccountChangeListController.h"
#import "TransferManagerController.h"
#import "WeekGiveListController.h"
#import "LillyGoldController.h"
#import "LillyGoldLsitController.h"

@interface SellerPreFectureTableViewController ()

@property (nonatomic,strong)NSArray *sellerArray;

@property (nonatomic,strong)UIView *centerView;

@end

//static NSString *const reuseIdentifier = @"reuseIdentifier";

@implementation SellerPreFectureTableViewController

- (NSArray *)sellerArray {
    if (!_sellerArray) {
        _sellerArray = @[@"商家合作专区",@"合作记录",@"营业额结算",@"营业额结算明细",@"销售订单",@"账户转换",@"账户转换记录",@"转账管理",@"每周奖励记录",@"让利金转换",@"让利金转换记录"];
    }
    return _sellerArray;
}
//
//- (void)viewWillAppear:(BOOL)animated
//{
//    [super viewWillAppear:animated];
//    [self.navigationController setNavigationBarHidden:NO animated:YES];
//    
//    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
//        
//        [self.tableView setSeparatorInset:UIEdgeInsetsMake(0, -25, 0, 0)];
//        
//    }
//}
//
//- (void)viewDidLoad {
//    [super viewDidLoad];
//    
//    self.title = @"商家专区";
//    
//    self.tableView.backgroundColor = BACKGROUND_COLOR;
//    self.tableView.tableFooterView = [[UIView alloc] init];
//}
//
//- (void)didReceiveMemoryWarning {
//    [super didReceiveMemoryWarning];
//    // Dispose of any resources that can be recreated.
//}
//
//#pragma mark - Table view data source
//
//
//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//    return self.sellerArray.count;
//}
//
//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
//    
//    if (!cell) {
//        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
//        
//        cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        cell.textLabel.font = FONT(15);
//    }
//    
//    cell.textLabel.text = self.sellerArray[indexPath.row];
//    
//    return cell;
//}
//
//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//    
//    switch (indexPath.row) {
//        case 0:
//        {
//            SellerCooperateTableViewController *cooperate = [[SellerCooperateTableViewController alloc] init];
//            cooperate.cashStr = self.cashStr;
//            [self.navigationController pushForm:self.navigationController pushToAndHidden:cooperate];
//        }
//        break;
//            
//        case 1:
//        {
//            cooperateRecodeViewController *cooperate = [[cooperateRecodeViewController alloc] init];
//            [self.navigationController pushForm:self.navigationController pushToAndHidden:cooperate];
//        }
//            break;
//            
//        case 2:
//        {
//            TurnOverBalanceTableViewController *balance = [[TurnOverBalanceTableViewController alloc] init];
//            [self.navigationController pushForm:self.navigationController pushToAndHidden:balance];
//        }
//            break;
//            
//        case 3:
//        {
//            TurnOverItemizedTableViewController *itemized = [[TurnOverItemizedTableViewController alloc] init];
//            [self.navigationController pushForm:self.navigationController pushToAndHidden:itemized];
//        }
//            break;
//            
//        case 4:
//        {
//            SellRecodeTableViewController *recode = [[SellRecodeTableViewController alloc] init];
//            [self.navigationController pushForm:self.navigationController pushToAndHidden:recode];
//        }
//            break;
//            
//        case 5:
//        {
//            AccountChangeController *changeVC = [[AccountChangeController alloc] init];
//            [self.navigationController pushForm:self.navigationController pushToAndHidden:changeVC];
//        }
//            break;
//            
//            
//        case 6:
//        {
//            AccountChangeListController *changeListVC = [[AccountChangeListController alloc] init];
//            [self.navigationController pushForm:self.navigationController pushToAndHidden:changeListVC];
//        }
//            break;
//            
//        case 7:
//        {
//            TransferManagerController *transVC = [[TransferManagerController alloc] init];
//            [self.navigationController pushForm:self.navigationController pushToAndHidden:transVC];
//        }
//            break;
//            
//        default:
//        {
//            WeekGiveListController *weekVC = [[WeekGiveListController alloc] init];
//            [self.navigationController pushForm:self.navigationController pushToAndHidden:weekVC];
//        }
//            break;
//    }
//
//}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"商家专区";
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.view.backgroundColor = BACKGROUND_COLOR;
    [self _initCenterView];
}

- (void)_initCenterView {
    
    self.centerView = [[UIView alloc] init];
//    self.centerView.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:self.centerView];
    
    [self.centerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top);
        make.centerX.equalTo(self.view.mas_centerX);
        make.width.mas_equalTo(WIDTH);
        make.height.mas_equalTo(WIDTH + 100);
    }];
    
    for (int i = 0; i < self.sellerArray.count; ++i) {
        
        CGFloat HIGH = (WIDTH)/3;
        
        int maxCol = 3;
        CGFloat col = i % maxCol;
        CGFloat row = i / maxCol;
        
        CGRect frame = CGRectMake(col*WIDTH/3 + 5,row*HIGH + 5,WIDTH/3 - 10, HIGH - 10);
//        NSLog(@"%f---%f---%f",frame.origin.y,row,HIGH);
        UIView *menubackView = [[UIView alloc] initWithFrame:frame];
        menubackView.tag = i;
        menubackView.layer.cornerRadius = 10;
        menubackView.layer.masksToBounds = YES;
        menubackView.backgroundColor = [UIColor whiteColor];
        [self.centerView addSubview:menubackView];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didClickMineMenuViewList:)];
        
        [menubackView addGestureRecognizer:tap];
        
        CGFloat frameWidth = frame.size.width;
        //图
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,5, frameWidth, frameWidth/2+5)];
        //        imageView.layer.cornerRadius = frameWidth/2;
        //        imageView.layer.masksToBounds = YES;
        //        imageView.contentMode = UIViewContentModeScaleToFill;
        //        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"wode_0%d",i + 1]];
        
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"合作商家_0%d",i+1]];
        imageView.contentMode = UIViewContentModeCenter;
        [menubackView addSubview:imageView];
        
        //文字
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(imageView.frame)+5,WIDTH/3 -10, 20)];
        titleLabel.font = [UIFont systemFontOfSize:15];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.text = [NSString stringWithFormat:@"%@",self.sellerArray[i]];
        titleLabel.textColor = [UIColor grayColor];
        [menubackView addSubview:titleLabel];
        
//        if (i == 7) {
//            self.lastLabel = titleLabel;
//            self.lastImageView = imageView;
//        }
//        
//        CGFloat x = 0.0;
//        CGFloat y = 0.0;
//        CGFloat w = 0.0;
//        CGFloat h = 0.0;
//        CGFloat width = WIDTH/4;
//        CGFloat height = HEIGHT/4;
//        switch (i) {
//            case 0:
//                x = width-1;
//                y = 3;
//                w = 1;
//                h = height - 6;
//                break;
//                
//            case 1:
//                x = width * 2;
//                y = 3;
//                w = 1;
//                h = height - 6;
//                break;
//                
//            case 2:
//                x = width * 3;
//                y = 3;
//                w = 1;
//                h = height - 6;
//                break;
//                
//                
//            case  3:
//                self.titleLabel = titleLabel;
//                
//                break;
//                
//            case 4:
//                x = 15;
//                y = height/2;
//                w = WIDTH - 30;
//                h = 1;
//                
//                self.unReadLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(imageView.frame)-15, -3, 20, 20)];
//                self.unReadLabel.backgroundColor = [UIColor redColor];
//                self.unReadLabel.textColor = [UIColor whiteColor];
//                self.unReadLabel.layer.cornerRadius = 10;
//                self.unReadLabel.layer.masksToBounds = YES;
//                self.unReadLabel.textAlignment = NSTextAlignmentCenter;
//                self.unReadLabel.font = [UIFont systemFontOfSize:12];
//                self.unReadLabel.text = self.UnReadCount;
//                self.unReadLabel.hidden = YES;
//                [menubackView addSubview:self.unReadLabel];
//                
//                break;
//                
//            case 5:
//                x = 15;
//                y = height;
//                w = WIDTH - 15;
//                h = 1;
//                break;
//                
//            default:
//                break;
//        }
//        
//        if (i == 0 || i == 1 || i == 4 || i == 2 || i == 5) {
//            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(x, y, w, h)];
//            view.backgroundColor = BACKGROUND_COLOR;
//            [self.contentView addSubview:view];
//        }
        
    }
}

- (void)didClickMineMenuViewList:(UITapGestureRecognizer *)sender {
    
    switch (sender.view.tag) {
        case 0:
        {
            SellerCooperateTableViewController *cooperate = [[SellerCooperateTableViewController alloc] init];
            cooperate.cashStr = self.cashStr;
            [self.navigationController pushForm:self.navigationController
                                pushToAndHidden:cooperate];
        }
            break;
            
        case 1:
        {
            cooperateRecodeViewController *cooperate = [[cooperateRecodeViewController alloc] init];
            [self.navigationController pushForm:self.navigationController
                                pushToAndHidden:cooperate];
        }
            break;
            
        case 2:
        {
            TurnOverBalanceTableViewController *balance = [[TurnOverBalanceTableViewController alloc] init];
            [self.navigationController pushForm:self.navigationController
                                pushToAndHidden:balance];
        }
            break;
            
        case 3:
        {
            TurnOverItemizedTableViewController *itemized = [[TurnOverItemizedTableViewController alloc] init];
            [self.navigationController pushForm:self.navigationController
                                pushToAndHidden:itemized];
        }
            break;
            
        case 4:
        {
            SellRecodeTableViewController *recode = [[SellRecodeTableViewController alloc] init];
            [self.navigationController pushForm:self.navigationController
                                pushToAndHidden:recode];
        }
            break;
            
        case 5:
        {
            AccountChangeController *changeVC = [[AccountChangeController
                                                  alloc] init];
            [self.navigationController pushForm:self.navigationController
                                pushToAndHidden:changeVC];
        }
            break;
            
            
        case 6:
        {
            AccountChangeListController *changeListVC = [[AccountChangeListController alloc] init];
            [self.navigationController pushForm:self.navigationController
                                pushToAndHidden:changeListVC];
        }
            break;
            
        case 7:
        {
            TransferManagerController *transVC = [[TransferManagerController alloc] init];
            [self.navigationController pushForm:self.navigationController
                                pushToAndHidden:transVC];
        }
            break;
            
        case 8:
        {
            WeekGiveListController *weekVC = [[WeekGiveListController alloc] init];
            [self.navigationController pushForm:self.navigationController
                                pushToAndHidden:weekVC];
        }
            break;
            
        case 9:
        {
            LillyGoldController *lillyVC = [[LillyGoldController alloc] init];
            [self.navigationController pushForm:self.navigationController
                                pushToAndHidden:lillyVC];
        }
            break;
            
        default:
        {
            LillyGoldLsitController  *listVC = [[LillyGoldLsitController alloc] init];
            [self.navigationController pushForm:self.navigationController pushToAndHidden:listVC];
        }
            break;
    }
}


@end
